<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编写日报</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/js/jquery.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/myAjax.js"></script>
    <script src="../../js/utlis/edit.js"></script>
</head>
<body>
<div style="display: flex;justify-content: center;  margin-top: 10px;">
    <div style="border:3px solid #276f58; padding: 10px">
        <div type="hidden" id="dailyId"></div>
        <div style="display: flex;justify-content: center">
            <div style="margin-left: 10px">姓名：<input type="text" id="name" style="height: 30px;"></div>
            <div style="margin-left: 10px">日期：<input type="text" id="writeTime" style="height: 30px;"></div>
            <div style="margin-left: 10px">班主任：
                <select id="classTeacher" style="height: 35px;width: 170px">

                </select>
            </div>
            <div style="margin-left: 10px">教练：<input type="text" id="coach" style="height: 30px;"></div>
        </div>
        <div style="margin-top: 20px">
            <div>学习内容：</div>
            <div><textarea type="text" id="content" placeholder="请输入内容" style="width: 100%;height: 100px"></textarea></div>
        </div>
        <div style="margin-top: 20px">
            <div>收获：</div>
            <div><textarea type="text" id="reap" placeholder="请输入内容" style="width: 100%;height: 100px"></textarea></div>
        </div>
        <div style="margin-top: 20px">
            <div>不足：</div>
            <div><textarea type="text" id="deficiency" placeholder="请输入内容" style="width: 100%;height: 100px"></textarea></div>
        </div>
        <div style="margin-top: 20px">
            <div>意见反馈：</div>
            <div><textarea type="text" id="suggestion" placeholder="请输入内容" style="width: 100%;height: 100px"></textarea></div>
        </div>
        <div style="line-height: 40px;margin-left: 300px">
            <input type="button" value="保存修改" onclick="editAdd('/d/daily/edit',getData())"
                   style="border-radius: 5px;width: 80px;height: 30px; background-color: #009E94"></div>
    </div>
</div>
</body>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#writeTime' //指定元素
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm'
        });
    });
   findTeacher();
    function findTeacher() {
        let result = myAjax('/d/daily/findTeacher', 'get', {});
        console.log(result);
        if (result.code === 200) {
            let html = "<option value='0'>全部</option>";
            for (let i = 0; i < result.data.length; i++) {
                html += '<option value="' + result.data[i].id + '">' + result.data[i].nickName + '</option>'
            }
            $("#classTeacher").html(html);
        }
    }
    findById();
    function findById() {
     let id = sessionStorage.getItem("dailyId");
     let result = myAjax('/d/daily/findById','post',{id:id});
     if (result.code===200){
         $("#name").val(result.data.name);
         $('#classTeacher option').filter(function () {
             return $(this).text() == result.data.classTeacher;
         }).prop("selected", true);
         $("#coach").val(result.data.coach);
         $("#writeTime").val(result.data.writeTime);
         $("#content").val(result.data.content);
         $("#reap").val(result.data.reap);
         $("#suggestion").val(result.data.suggestion);
         $("#deficiency").val(result.data.deficiency);
     }else {
         layer.msg("查询失败");
     }
    }
    function getData() {
        let data = {
            id:sessionStorage.getItem("dailyId"),
            name:$("#name").val(),
            coach:$("#coach").val(),
            writeTime:$("#writeTime").val(),
            classTeacher:$("#classTeacher").find("option:selected").text(),
            content:$("#content").val(),
            reap:$("#reap").val(),
            deficiency:$("#deficiency").val(),
            suggestion:$("#suggestion").val(),
        }
        return data
    }
</script>
</html>